<div class="form wide">
<?php if (!$this->get('Lookup[type]')): ?>
<?php $form=$this->beginWidget('FActiveForm', array(
    'id'=>'lookup-form',
    'enableAjaxValidation'=>false,
    'action'=>$this->createUrl('/Admin/lookup/create'),
)); ?>
<?php else :?>
<?php $form=$this->beginWidget('FActiveForm', array(
    'id'=>'lookup-form',
    'enableAjaxValidation'=>false,
)); ?>
<?php endif;?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php //echo $form->errorSummary($model); ?>

    <?php if (! $model->IsNewRecord) echo $form->hiddenField($model, "id") ; ?>
    <div class="row">
        <?php echo $form->labelEx($model,'name'); ?>
        <?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>128)); ?>
        <?php echo $form->error($model,'name'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'code'); ?>
        <?php echo $form->textField($model,'code'); ?>
        <?php echo $form->error($model,'code'); ?>
    </div>
    
    <?php if ($this->get('Lookup[type]')): ?>
      <?php $model->type = $this->get('Lookup[type]');?>
      <?php echo $form->hiddenField($model,'type');?>
    <?php elseif(!$model->IsNewRecord):?>
    <?php echo $form->hiddenField($model,'type');?>
    <?else: ?>
    <div class="row">
        <?php echo $form->labelEx($model,'type'); ?>
        <?php echo $form->textField($model,'type'); ?>
        <?php echo $form->error($model,'type'); ?>
    </div>
    <?php endif;?>
        

    <!--<div class="row">
        <?php echo $form->labelEx($model,'position'); ?>
        <?php echo $form->textField($model,'position'); ?>
        <?php echo $form->error($model,'position'); ?>
    </div>-->

    <div class="row buttons">
        
        <?php if ($this->get('Lookup[type]')): ?>
        <?php echo CHtml::submitButton('Save',array('name'=>'save_only')); ?>
        <?php echo CHtml::submitButton('Save and add another one',array('name'=>'save_add')); ?>  
        <?php else:?>  
        <?php echo CHtml::submitButton('Save'); ?>
        <?php endif;?>
    </div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php 
$script = "
    parent.$.popupClosed = function (){
        //parent.$('#lookup-grid').load(
//            parent.location + ' #lookup-grid',
//            null,
//            parent.$('#lookup-grid td.button-column a.update').attr('class','fancy-iframe'),
//            parent.initFancybox,
//            parent.enableSort
//        );
    parent.window.location.reload();
    }
";

cs()->registerScript('update-grid',$script, CClientScript::POS_READY);
?>